package entity

/**
* @author aFun
* @data 2025/4/10 01:01
* @email: afunaaa222@163.com / 1030935903
* @address: Guangdong University of Technology, China
 */

import (
	"database/sql/driver"
	"encoding/json"
	"fmt"
	"github.com/jinzhu/gorm"
)

type FloorReward struct {
	Floor int8  // 领取的层
	Pos   int8  // 领取的位置
	Num   int32 // 领取次数
}

type FloorRewardedList []FloorReward

func (f FloorRewardedList) Value() (driver.Value, error) {
	return json.Marshal(f)
}

func (f *FloorRewardedList) Scan(value interface{}) error {
	return json.Unmarshal(value.([]byte), f)
}

type CumulativeRewardedList []int64

func (c CumulativeRewardedList) Value() (driver.Value, error) {
	return json.Marshal(c)
}

func (c *CumulativeRewardedList) Scan(value interface{}) error {
	return json.Unmarshal(value.([]byte), c)
}

type LuckyDraw struct {
	gorm.Model
	Role_id     uint
	Camp_id     int32 `gorm:"default:0"` // 活动id
	Prev_change int8  `gorm:"default:0"` // 上一次抽奖状态, 0表示没抽过奖
	Cur_floor   int8  `gorm:"default:0"` // 当前所在层
	// [{floor, pos, num}, ...]
	FloorRewarded      FloorRewardedList      `gorm:"type:json"`
	CumulativeRewarded CumulativeRewardedList `gorm:"type:json"`
	Draw_num           int64                  `gorm:"default:0"`     // 累计抽取次数
	Consumed_tokens    int64                  `gorm:"default:0"`     // 累计消耗代币数
	Is_end             bool                   `gorm:"default:false"` // 标记本轮是否结束
}

func (ld *LuckyDraw) String() string {
	return fmt.Sprintf("LuckyDraw: Prev_change: %d, Cur_floor: %d, FloorRewarded: %s, CumulativeRewarded: %s, "+
		"Draw_num: %d, Consumed_tokens: %d, Is_end: %t", ld.Prev_change, ld.Cur_floor, ld.FloorRewarded, ld.CumulativeRewarded, ld.Draw_num, ld.Consumed_tokens, ld.Is_end)
}

type LuckyDrawRank struct {
	Role_id         uint
	Draw_num        int64
	Consumed_tokens int64
}
